﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

//Top Meeting
using TopVisionVideoStream;
using LayeredSkin.Forms;
using LayeredSkin.Controls;
using System.Diagnostics;
using Top_Meeting.UI;

namespace Top_Meeting
{
    public partial class Form1 : LayeredForm
    {
        OpenFileDialog openFileDialog = new OpenFileDialog();
        Dictionary<string, Image> skinRes = new Dictionary<string, Image>();
        string defaultLayout = @"Layout\SkinLayout_001.tvrs";

        public Form1()
        {
            InitializeComponent();

            TVVS.Init(this);

            this.Font = TMFont.Font_Hei;

            BackColor = Color.FromArgb(0, 255, 255, 255);

            layBtnClose.Click += LayBtnClose_Click;
            //layBtnClose.MouseEnter += Button_MouseEnter;
            //layBtnClose.MouseLeave += Button_MouseLeave;

            layPanelMain.MouseDown += LayPanelMain_MouseDown;

            UpdateLayout();
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);
            TVVS.Dispose();
        }

        private void Button_MouseLeave(object sender, EventArgs e)
        {
            var btn = sender as LayeredButton;
            if (btn != null)
            {
                btn.BackColor = Color.FromArgb(0, 255, 255, 255);
            }
        }

        private void Button_MouseEnter(object sender, EventArgs e)
        {
            var btn = sender as LayeredButton;
            if (btn != null)
            {
                btn.BackColor = Color.FromArgb(255, 128, 128, 128);
            }
        }

        private void LayPanelMain_MouseDown(object sender, MouseEventArgs e)
        {
            this.OnMouseDown(e);
        }

        private void LayBtnClose_Click(object sender, EventArgs e)
        {
            Hide();
            Close();
        }

        private void PanelMain_MouseDown(object sender, MouseEventArgs e)
        {
            this.OnMouseDown(e);
        }

        private void UpdateLayout()
        {
            skinRes = Helper.ReadSkinResources(defaultLayout);

            if (skinRes.Count > 0)
            {
                layPanelMain.BackgroundImage = skinRes["登录面板.png"];
                this.Size = skinRes["登录面板.png"].Size;

                layBtnClose.NormalImage = skinRes["关闭按钮.png"];
                layBtnClose.HoverImage = skinRes["关闭按钮（悬停）.png"];
                layBtnClose.Size = skinRes["关闭按钮.png"].Size;

                Point btnClosePoint = new Point();
                btnClosePoint.X = (layPanelMain.Size.Width - layBtnClose.Width) - layPanelMain.Padding.Right;
                btnClosePoint.Y = layPanelMain.Padding.Top;

                layBtnClose.Location = btnClosePoint;

                layPnlAccountInput.BackgroundImage = skinRes["用户名输入框.png"];
                layPnlAccountInput.Size = skinRes["用户名输入框.png"].Size;
                layTxtAccount.Font = TMFont.Font_Hei_14;
            }

            CenterToScreen();
        }
    }
}
